package thread.queuq;

public class Queue {
    private int n;
    boolean flag =false;
    public synchronized int get() throws InterruptedException {
        if(!flag){
            wait();
        }
        System.out.println("获取："+n);
        flag = false;
        notifyAll();
        return n;
    }
    public synchronized void set(int n) throws InterruptedException {
        /*有数据*/
        if(flag){
            wait();
        }
        this.n = n;
        flag = true;
        notifyAll();
        System.out.println("设置："+n);
    }

}
